package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictoptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dictoption/")
public class dictoptionController {

    @Autowired
    private DictoptionService dictoptionService;

    @GetMapping("/select")
    public JsonResult selectDictOption(DictOptionQuery dictQuery){
        log.debug("查询DictOption参数: dictQuery={}",dictQuery);
        List<DictOptionVO> list= dictoptionService.selectDictOption(dictQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    public JsonResult saveDictOption(DictOptionSaveParam dictSaveParam){
        log.debug("保存DictOption参数: dictSaveParam={}",dictSaveParam);
        dictoptionService.saveDictOption(dictSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteDictOptionByCode(@PathVariable Long id){
        log.debug("删除DictOption参数: id={}",id);
        dictoptionService.deleteDoctOption(id);
        return JsonResult.ok();
    }

    @GetMapping("select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code){
        log.debug("字典项应用参数:  code :{}",code);
        List<DictOptionVO> list=  dictoptionService.selectDictOptionByCode(code);
        log.debug("list = "+list);
        return JsonResult.ok(list);
    }
}
